package com.qfedu.controller;

import com.qfedu.model.Developer;
import com.qfedu.model.Developer;
import com.qfedu.page.PageResult;
import com.qfedu.page.QueryPageBean;
import com.qfedu.page.Result;
import com.qfedu.service.DeveloperService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author LiJH
 * @date 2023-02-10
 */
@RestController
@RequestMapping("developer")
public class DeveloperController {
    @Autowired
    private DeveloperService developerService;
    @PostMapping("findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult page = developerService.findPage(queryPageBean);
        return page;
    }
    @GetMapping("findDeveByDid")
    public Result findDeveByDid(String did){
        Developer deveByDid = developerService.findDeveByDid(did);
        //查询成功
        if (ObjectUtils.notEqual(deveByDid, null)) {
            return Result.successResult("查询成功",deveByDid);
        } else {
            return Result.failResult("查询失败");
        }
    }
    @PostMapping("addDeveloper")
    public Result addDeveloper(@RequestBody Developer developer){
        int i = developerService.addDeveloper(developer);
        Result result = new Result();
        if (i>0){
            result.setFlag(true);
            result.setMessage("添加成功！");
        }else {
            result.setFlag(false);
            result.setMessage("添加失败！");
        }
        return result;
    }

    @PostMapping("editDeveloper")
    public Result editDeveloper(@RequestBody Developer developer){
        Result result = new Result();
        int i = developerService.editDeveloper(developer);
        if (i>0){
            result.setFlag(true);
            result.setMessage("更新成功！");
        }else {
            result.setFlag(false);
            result.setMessage("更新失败！");
        }
        return result;
    }

    @GetMapping("deleteByDid")
    public Result deleteByDid(String did){
        int i = developerService.deleteByDid(did);
        Result result = new Result();
        if (i>0){
            result.setFlag(true);
            result.setMessage("删除成功！");
        }else {
            result.setFlag(false);
            result.setMessage("删除失败！");
        }
        return result;
    }
}